package cq.com.cn.servlet;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import cq.com.cn.model.BooksModel;
import cq.com.cn.model.UserModel;
import cq.com.cn.service.BooksService;
import cq.com.cn.service.UserService;
import cq.com.cn.utils.AjaxUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/query/checkEmail.do")
public class CheckUserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //参数处理
        String email=req.getParameter("email");
        //业务处理
        UserService userService=new UserService();
        UserModel user = userService.queryUserWithEmail(email);

        //数据返回到页面
        JsonObject objs=new JsonObject();
        if(user==null){
            objs.addProperty("rs",true);
        }else{
            objs.addProperty("rs",false);
        }
        AjaxUtils.ajaxHtml(objs.toString(),resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
    
}
